home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------
-
- AOCE Post Office Protocol (POP) / Simple Mail Transfer Protocol (SMTP)
- Mail Service Access Module
-
- written by Steve Falkenburg-- MacDTS
- ©1991-1993 Apple Computer, Inc.
-
- --------------
- change history
- --------------
-
- SJF 02/19/93 update for beta build b1
- SJF 10/29/92 update to a11 a11
- SJF 06/08/92 update to a8 a8
- SJF 02/15/92 first working version a4.5
- SJF 10/16/91 initial coding a3
-
- ---------------------------------------------------------------------*/
-
- #ifndef __OCE__
- #include <OCE.h>
- #endif
-
- #ifndef __OCEAUTHDIR__
- #include <OCEAuthDir.h>
- #endif
-
- #include <string.h>
-
- #include "const.h"
- #include "gwerrors.h"
- #include "mytypes.h"
- #include "globals.h"
- #include "utils.h"
- #include "gatewaystuff.h"
- #include "authstuff.h"
-
- OSErr InitAuthStuff(void)
- {
- AuthParamBlock authBlock;
- OSErr err;
- Str255 appName;
- short resRefNum;
- Handle hParms;
-
- gAuthInCriticalSection = 0;
- gAuthUnlocked = false;
- gAuthRefresh = false;
-
- err = AuthGetLocalIdentity(&authBlock,false);
- if (err==noErr) {
- gAuthUnlocked = true;
- gAuthRefresh = true;
- }
- gLocalIdentity = authBlock.getLocalIdentityPB.theLocalIdentity;
-
- GetAppParms(appName,&resRefNum,&hParms);
- authBlock.localIdentityQInstallPB.notifyProc = AuthNotifyProc;
- authBlock.localIdentityQInstallPB.notifyFlags = kNotifyLockMask|kNotifyUnlockMask;
- authBlock.localIdentityQInstallPB.appName = appName;
- err = AuthAddToLocalIdentityQueue(&authBlock,false);
-
- return err;
- }
-
-
- OSErr ExitAuthStuff(void)
- {
- AuthParamBlock authBlock;
- OSErr err;
-
- TraceExecution("\pExitAuthStuff");
-
- authBlock.localIdentityQRemovePB.notifyProc = AuthNotifyProc;
- err = AuthRemoveFromLocalIdentityQueue(&authBlock,false);
- return err;
- }
-
-
- void EnterAuthCriticalSection(void)
- {
- gAuthInCriticalSection++;
- }
-
-
- void ExitAuthCriticalSection(void)
- {
- gAuthInCriticalSection--;
- }
-
-
- OSErr CheckAuthRefresh(void)
- {
- OSErr err;
- AuthParamBlock authBlock;
-
- // exit if we don't need to refresh data
- if (!gAuthRefresh)
- return noErr;
-
- if (gAuthUnlocked) {
- AuthGetLocalIdentity(&authBlock,false); // they might have just configured, so this wouldn't be correct yet
- gLocalIdentity = authBlock.getLocalIdentityPB.theLocalIdentity;
- err = ReadDirectoryInfo();
- }
- else
- err = ClearDirectoryInfo();
-
- gAuthRefresh = false;
-
- return err;
- }
-
-
- /*--------------------------------------------------------------------------------*/
-
-
- pascal Boolean AuthNotifyProc(long clientData, AuthLocalIdentityOp callValue,
- AuthLocalIdentityLockAction actionValue, LocalIdentity identity)
- {
- #pragma unused (clientData,identity)
-
- #define kAllowLock false
- #define kPreventLock true
-
- // if they're requesting a lock, deny only if we're in a critical auth section
-
- if (actionValue==kAuthLockPending)
- return (gAuthInCriticalSection!=0);
-
- // set locked/unlocked flag
-
- if (callValue==kAuthUnlockLocalIdentityOp)
- gAuthUnlocked = true;
- else
- gAuthUnlocked = false;
-
- gAuthRefresh = true;
- gWakeUp = true; // set a flag to make sure we affect the *next* WaitNextEvent
- WakeUpProcess(&gOurPSN);
-
- return kAllowLock;
- }
-
-
- // ReadDirectoryInfo
- //
- // this is called when we need to fill in the name and password for the external system
- // for each slot, we read in the name and password for the directory
-
- OSErr ReadDirectoryInfo(void)
- {
- short slotIndex;
- OSErr err;
-
- err = noErr;
-
- for (slotIndex=0;slotIndex<gNumSlots && err==noErr;slotIndex++)
- err = ReadSingleDirectoryInfo(&gSlotDatabase[slotIndex].directoryName,
- &gSlotDatabase[slotIndex].discriminator,
- &gSlotDatabase[slotIndex].dirIdentity);
-
- return err;
- }
-
-
- // ReadSingleDirectoryInfo
- //
- // called for each slot from ReadDirectoryInfo, this call does the actual work of reading the
- // info into the database
-
- OSErr ReadSingleDirectoryInfo(const RString *dirName,const DirDiscriminator *discriminator,DirIdentity *dirIdentity)
- {
- RString rsNativeName,rsPassword,ridName,ridType;
- PackedRLI pRLI;
- RecordID identRID;
- OCESetupGetDirectoryInfoPB authBlock;
- OSErr err;
-
- TraceExecution("\pREADDIRECTORYINFO");
-
- rsNativeName.charSet = smRoman;
- rsNativeName.dataLength = kRStringMaxChars;
- rsPassword.charSet = smRoman;
- rsPassword.dataLength = kRStringMaxChars;
- ridName.charSet = smRoman;
- ridName.dataLength = kRStringMaxChars;
- ridType.charSet = smRoman;
- ridType.dataLength = kRStringMaxChars;
- pRLI.dataLength = 0;
- identRID.rli = &pRLI;
- OCESetCreationIDtoNull(&identRID.local.cid);
- identRID.local.recordName = &ridName;
- identRID.local.recordType = &ridType;
-
- authBlock.directoryName = (DirectoryName *)dirName;
- authBlock.discriminator = *discriminator;
- authBlock.recordID = &identRID;
- authBlock.nativeName = &rsNativeName;
- authBlock.password = &rsPassword;
- err = OCESetupGetDirectoryInfo((AuthParamBlockPtr)&authBlock,false);
- if (err!=noErr)
- return err;
-
- r2cString(&ridName,dirIdentity->userName);
- r2cString(&rsPassword,dirIdentity->password);
- dirIdentity->valid = true;
-
- return err;
- }
-
-
- OSErr ClearDirectoryInfo(void)
- {
- DirIdentity *dirIdentity;
- short slotIndex;
-
- TraceExecution("\pCLEARDIRECTORYINFO");
-
- for (slotIndex=0;slotIndex<gNumSlots;slotIndex++) {
- dirIdentity = &gSlotDatabase[slotIndex].dirIdentity;
- dirIdentity->userName[0] = 0;
- dirIdentity->password[0] = 0;
- dirIdentity->valid = false;
- }
-
- return noErr;
- }
-
-